package com.xauto.pioneer.appuser.activity.mine.user;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import com.xauto.pioneer.appuser.R;
import com.xauto.pioneer.appuser.activity.BaseActivity;
import com.xauto.pioneer.appuser.activity.mine.VoucherListActivity;
import com.xauto.pioneer.appuser.activity.mine.balance.DepositBalanceActivity;
import com.xauto.pioneer.appuser.activity.user_aptitude.UsreAptitudeActivity;
import com.xauto.pioneer.appuser.http.API;
import com.xauto.pioneer.appuser.http.BaseLHttpHandler;
import com.xauto.pioneer.appuser.http.LHttpLib;
import com.xauto.pioneer.appuser.model.JSONStatus;
import com.xauto.pioneer.appuser.model.MemberMessageDateil;
import com.xauto.pioneer.appuser.view.TopBar;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by lsx on 2018-03-08.
 */

public class MemberMessageDetailActivity extends BaseActivity {

    @Bind(R.id.tvMessageTitle)
    TextView tvMessageTitle;
    @Bind(R.id.tvMessageDate)
    TextView tvMessageDate;
    @Bind(R.id.message_datil_button)
    TextView message_datil_button;
    @Bind(R.id.topBar)
    TopBar topBar;
    String MessageTitle="";
    String MessageData="";
    String member_message_id="0";
    MemberMessageDateil MemberMessageDateil;
    /**
     *
     * @param context
     */
    public static void startAction(Activity context, String member_message_id, String Date){
        Intent intent = new Intent(context,MemberMessageDetailActivity.class);
        intent.putExtra("member_message_id",member_message_id);
        intent.putExtra("Date",Date);
        context.startActivityForResult(intent,1000);
    }
    @Override
    protected int getContentView() {
        return R.layout.ac_member_message_datils;
    }

    @Override
    protected void initView() {
        topBar.showView(TopBar.LEFT_IMAGE_BTN, TopBar.TITLE);
        topBar.setImage(TopBar.LEFT_IMAGE_BTN, R.mipmap.ic_common_left);
        topBar.setText(TopBar.TITLE, R.string.mine_message_datile);
        topBar.setLeftOnClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    @OnClick({R.id.message_datil_button})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.message_datil_button:
                if(MemberMessageDateil.link_route.equals("member_aptitude")){
                    startActivity(new Intent(mContext, UsreAptitudeActivity.class));
                }
                if(MemberMessageDateil.link_route.equals("phone")){
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+MemberMessageDateil.link_value));
                    startActivity(intent);
                }
                if(MemberMessageDateil.link_route.equals("member_deposit_pay")){
                    startActivity(new Intent(mContext, DepositBalanceActivity.class));
                }
                if(MemberMessageDateil.link_route.equals("member_vouchlist")){
                    VoucherListActivity.startAction(MemberMessageDetailActivity.this,false,"",101, API.GET_VOUCHER_LIST);
                }
                break;
        }
    }
    @Override
    protected void initData() {
        member_message_id= getIntent().getStringExtra("member_message_id");
        MessageData = getIntent().getStringExtra("Date");
    }
    @Override
    protected void onStart() {
        super.onStart();
        loadMessageDetail();
    }
    /**
     * 加载详情信息
     */
    private void loadMessageDetail() {
        new LHttpLib().getMemberMessageDateil(mContext, memberId, member_message_id, new BaseLHttpHandler(mContext, true, true) {
            @Override
            public void onSuccess(JSONStatus jsonStatus) {
                super.onSuccess(jsonStatus);
                MemberMessageDateil = new MemberMessageDateil().parse(jsonStatus.data.optJSONObject("member_message_info"));
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        showMessageDetail();
                    }
                });
            }
        });
    }

    /**
     * 显示相关数据
     */
    private void showMessageDetail() {
        if(MemberMessageDateil.link_route.equals("")){
            message_datil_button.setVisibility(View.GONE);
        }
        tvMessageTitle.setText(MemberMessageDateil.member_message_content);
        tvMessageDate.setText(MessageData);
    }
    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }


}
